﻿using System;
using TransferPost.Docking;

namespace TransferPost.Componts
{
    public class PostFormAttribute : Attribute
    {
        /// <summary>
        ///  
        /// </summary>
        public string FormName;

        public string FormNo;


        /// <summary>
        /// 是否支持多开
        /// </summary>
        public bool AllowMuti = false;
    }

    /// <summary>
    /// 很多窗体都在Tab中有个右键菜单，右击的里面有关闭，所以最好继承一下DockContent，
    /// 让其它窗体只要继承这个就有了这个右键菜单
    /// </summary>
    public class DockContentEx : DockContent
    {
        protected frmMain frm_Parent;


        public DockContentEx()
        {
            //绑定右键菜单
            BindMenuStrip();
        }

        private void BindMenuStrip()
        {
            System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
            // 
            // tsmiClose
            // 
            System.Windows.Forms.ToolStripMenuItem tsmiClose = new System.Windows.Forms.ToolStripMenuItem();
            tsmiClose.Name = "cms";
            tsmiClose.Size = new System.Drawing.Size(98, 22);
            tsmiClose.Text = "关闭";
            tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click);
            // 
            // tsmiALLClose
            // 
            System.Windows.Forms.ToolStripMenuItem tsmiALLClose = new System.Windows.Forms.ToolStripMenuItem();
            tsmiALLClose.Name = "cms";
            tsmiALLClose.Size = new System.Drawing.Size(98, 22);
            tsmiALLClose.Text = "全部关闭";
            tsmiALLClose.Click += new System.EventHandler(this.tsmiALLClose_Click);
            // 
            // tsmiApartFromClose
            // 
            System.Windows.Forms.ToolStripMenuItem tsmiApartFromClose = new System.Windows.Forms.ToolStripMenuItem();
            tsmiApartFromClose.Name = "cms";
            tsmiApartFromClose.Size = new System.Drawing.Size(98, 22);
            tsmiApartFromClose.Text = "除此之外全部关闭";
            tsmiApartFromClose.Click += new System.EventHandler(this.tsmiApartFromClose_Click);
            // 
            // tsmiClose
            // 
            cms.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            tsmiClose,tsmiApartFromClose,tsmiALLClose});
            cms.Name = "tsmiClose";
            cms.Size = new System.Drawing.Size(99, 26);
            this.TabPageContextMenuStrip = cms;
        }


        private void tsmiClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsmiALLClose_Click(object sender, EventArgs e)
        {
            foreach (var item in DockPanel.Contents)
            {
                if (item.DockHandler.DockState == DockState.Document)
                {
                    item.DockHandler.Hide();
                }
            }
        }

        /// <summary>
        /// 这里都是假的关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiApartFromClose_Click(object sender, EventArgs e)
        {
            foreach (var item in DockPanel.Contents)
            {
                if (item.DockHandler.DockState == DockState.Document)
                {
                    if (item != this)
                        item.DockHandler.Hide();
                }
            }
        }
    }
}
